﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PushDownAutomaton
{
    class DeltaPDA
    {
        private Dictionary<DeltaPDAKey, HashSet<DeltaPDAValue>> table;

        public DeltaPDA()
        {
            table = new Dictionary<DeltaPDAKey, HashSet<DeltaPDAValue>>();
        }

        public void SetTransition(PDAState currentState,
                                  char inputSymbol,
                                  String currentStackTop,
                                  PDAState nextState,
                                  DeltaPDAAction action,
                                  String pushSymbol)
        {
            DeltaPDAKey key = new DeltaPDAKey(currentState, inputSymbol, currentStackTop);
            DeltaPDAValue value = new DeltaPDAValue(nextState, action, pushSymbol);

            if (!table.ContainsKey(key))
                table[key] = new HashSet<DeltaPDAValue>();

            table[key].Add(value);
        }

        public HashSet<DeltaPDAValue> Evaluate(PDAState currentState,
                                               char inputSymbol,
                                               String currentStackTop)
        {
            DeltaPDAKey key = new DeltaPDAKey(currentState, inputSymbol, currentStackTop);
            return table[key];
        }

    }
}
